#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QApplication>
#include <QDebug>
MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    // --------------------------------------------
    // 增加主题逻辑
    mframe = new QFrameMainShortcut;
    ui->ui_mframe->addWidget(mframe);
    // --------------------------------------------
    // 修改软件外观

    QString title = "凝光阁-V"+ qApp->applicationVersion();
    qDebug() << __FILE__ << __LINE__ << title;
    this->setWindowTitle(title); //显示的名字增加版本号
    this->setWindowIcon(QIcon(":/icons/icon_user/condensed_light_pavilion.png"));
    this->show();

    // --------------------------------------------
    // 修改工具栏的图标
    ui->action_team_manager->setIcon(QIcon(":/icons/icon_user/team_manager.png"));
    ui->action_node_editor->setIcon(QIcon(":/icons/icon_user/simple_node.png"));

}

MainWindow::~MainWindow()
{
    delete ui;
}


void MainWindow::on_action_team_manager_triggered()
{
    u_team_manager_subs = new team_manager_subs;
    u_team_manager_subs->setWindowTitle("team_manager");
    mframe->setWidget(u_team_manager_subs); //设置目标设备
}


void MainWindow::on_action_node_editor_triggered()
{
    //创建编辑器
    editor = new QFrameEditorSimple(this,"A*"); //关闭文件信息按钮
    editor->setWindowTitle("Editor");
    editor->setWindowIcon(QIcon(":/icons/icon_user/simple_node.png"));


    u_node_editor_subs = new node_editor_subs;
    u_node_editor_subs->setWindowTitle("node_editor");
    editor->addWidget(u_node_editor_subs,u_node_editor_subs->windowTitle());

    connect(editor , &QFrameEditorSimple::dir_open_trig, u_node_editor_subs, &node_editor_subs::load ); //转发信号到嵌入的模块
    connect(editor , &QFrameEditorSimple::dir_save_trig, u_node_editor_subs, &node_editor_subs::save ); //转发信号到嵌入的模块

    mframe->setWidget(editor); //设置目标设备
}


void MainWindow::on_action_sync_software_triggered()
{
    u_software_update_subs = new software_update_subs;
    u_software_update_subs->show();
}


void MainWindow::on_action_log_edit_triggered()
{
    u_software_update_subs = new software_update_subs;
    u_software_update_subs->get_bug_file(); //读取bug记录文件
    delete u_software_update_subs; //释放对象
}


void MainWindow::on_action_theme_dark_triggered()
{
    u_software_update_subs = new software_update_subs;
    u_software_update_subs->set_app_theme("dark"); //读取bug记录文件
    delete u_software_update_subs; //释放对象
}


void MainWindow::on_action_theme_light_triggered()
{
    u_software_update_subs = new software_update_subs;
    u_software_update_subs->set_app_theme("light"); //读取bug记录文件
    delete u_software_update_subs; //释放对象
}


void MainWindow::on_action_help_doc_triggered()
{
    u_software_update_subs = new software_update_subs(nullptr,1); //切换到帮助文档
    u_software_update_subs->show();
}

